<?php

use Faker\Generator as Faker;

/*
|--------------------------------------------------------------------------
| Model Factories
|--------------------------------------------------------------------------
|
| This directory should contain each of the model factory definitions for
| your application. Factories provide a convenient way to generate new
| model instances for testing / seeding your application's database.
|
*/

$factory->define(App\User::class, function (Faker $faker) {
    return [
        'name' => $faker->name,
        'email' => $faker->unique()->safeEmail,
        'email_verified_at' => now(),
        'password' => '$2y$10$TKh8H1.PfQx37YgCzwiKb.KjNyWgaHb9cbcoQgdIVFlYg7B77UdFm', // secret
        'remember_token' => str_random(10),
    ];
});

$factory->define(App\Area::class, function (Faker $faker) {
    return [
        'name' => $faker->name,
    ];
});

$factory->define(App\Product::class, function (Faker $faker) {
    return [
        'name' => $faker->name,
        'ie' => str_random(),
        'ic' => str_random(20),
        'area_id' => function () {
            return factory('App\Area')->create()->id;
        },
        'lat' => $faker->latitude,
        'lng' => $faker->longitude,
    ];
});


$factory->define(App\Record::class, function (Faker $faker) {
    return [
        'product_id' => function () {
            return factory('App\Product')->create()->id;
        },
        'error' => '0000',
        'rs' => mt_rand(0, 99),
        'it' => mt_rand(240, 370),
        'et' => mt_rand(70, 130),
        'rh' => mt_rand(400, 500),
        'cp' => mt_rand(200, 500),
        '5k' => '00000',
        'dv' => '220',
        'da' => '400',
        'dw' => '8800',
        'dh' => mt_rand(4900, 7200),
        'ds' => mt_rand(1, 200),
        'dc' => mt_rand(1, 200),
        'df' => mt_rand(1, 200),
    ];
});



$factory->define(App\Warning::class, function (Faker $faker) {
    $created_at = $faker->dateTimeBetween('-5 days', 'now');
    return [
        'product_id' => function () {
            return factory('App\Product')->create()->id;
        },
        'is_handle' => 0,
        'created_at' => $created_at,
        'updated_at' => $created_at,
    ];
});
